angular.module('GiveStock')

.factory('GiveStockHomeService', ['$q', 'Http',
    function($q, Http) {
       // //获取备货看板数据 
       // function getGiveStockData (userId) {
       //      var defer = $q.defer();

       //      Http.post({
       //          url: "/api/Kanban/GetUpStreamKanban",
       //          data: {
       //              Parameter: {
       //                  userId: userId
       //              }
       //          }
       //      }).then(function (data) {
       //          defer.resolve(data);   
       //      }, function (err) {
       //          defer.reject(err);
       //      });

       //      return defer.promise;
       //  }
       //  //获取交接区数据
       //  function getConnectArea (terminalId) {
       //      var defer = $q.defer();

       //      Http.post({
       //          url: "/api/Kanban/queryConnectAreaByTerminal",
       //          data: {
       //              Parameter: {
       //                  uniqueID: terminalId,
       //                  isUp:true
       //              }
       //          }
       //      }).then(function (data) {
       //          defer.resolve(data); 
       //      }, function (err) {
       //          defer.reject(err);
       //      });

       //      return defer.promise;
       //  }

       //获取备货看板(上游)待转区信息
       function getTransferArea (workId) {
            var defer = $q.defer();
            Http.post({
                url: "/api/Kanban/queryTransferAreaByWork",
                data: {
                    Parameter: {
                        workId: workId,
                        isUp: true
                    }
                }
            }).then(function (data) {
                defer.resolve(data); 
            }, function (err) {
                defer.reject(err);
            });

            return defer.promise;
        }

      

        //获取要货看板(上游)数据
       function queryGiveStockData (wareHouseId,departmentId) {
            var defer = $q.defer();
            Http.post({
                url: "/api/Kanban/queryKanbanData",
                data: {
                    Parameter: {
                        wareHouseId: wareHouseId,
                        flag: "up",
                        departmentId:departmentId
                    }
                }
            }).then(function (data) {
                defer.resolve(data); 
            }, function (err) {
                defer.reject(err);
            });

            return defer.promise;
        }

        //查找到所有仓库
        function getAllWareHouse(){
            var defer = $q.defer();
            Http.post({
                url: "/api/Kanban/getAllWareHouse",
                data: {
                    Parameter: {
                        
                    }
                }
            }).then(function (data) {
                defer.resolve(data); 
            }, function (err) {
                defer.reject(err);
            });

            return defer.promise;
        }

        var wareHouse = {};
        var houses = [];

        return{
            //旧服务
            // getGiveStockData:getGiveStockData,
            // getConnectArea:getConnectArea
            //新服务
            getTransferArea:getTransferArea,
            queryGiveStockData:queryGiveStockData,
            getAllWareHouse:getAllWareHouse,
            //当前仓库
            wareHouse:wareHouse,
            //所有仓库
            houses:houses
        };
     
    }
]);
